package com.hall;

import com.sharecommon.auth.service.AuthService;
import dml.users.proc.KeepAliveSessionProcesses;
import erp.annotation.Process;
import erp.repository.TakeEntityException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class ProxyAuthService extends AuthService {

    @Autowired
    public ProxyAuthService(RedisTemplate redisTemplate, RedisMySessionRepository mySessionRepository) {
        KeepAliveSessionProcesses sessionProcesses = new KeepAliveSessionProcesses(mySessionRepository, null);
        setSessionProcesses(sessionProcesses);
        setSessionRepository(mySessionRepository);
    }


    public Long verifyToken(String token) {
        while (true) {
            try {
                return doVerifyToken(token);
            } catch (TakeEntityException e) {
                continue;
            }
        }
    }

    @Process
    public Long doVerifyToken(String token) {
        return super.verifyToken(token);
    }


}
